<?php


namespace app\appa\controller;


use app\appa\model\AppraModel;
use app\appa\model\MasterModel;
use app\appa\model\MastserModel;
use app\common\controller\Api;
use think\Request;

class Master extends Api
{
    //综合
    public function list1(Request $request)
    {
        $list = MasterModel::order('id','DESC')
            ->field('id,name,image,num')
            ->select();
        if (!$list){
            $this->error('暂无数据');
        }
        $this->success('查询成功',[
            'list' => $list
        ]);
    }

    //距离
    public function list2(Request $request)
    {
        $list = MasterModel::order('range','ASC')
            ->field('id,name,image,num')
            ->select();
        if (!$list){
            $this->error('暂无数据');
        }
        $this->success('查询成功',[
            'list' => $list
        ]);
    }

    //服务次数
    public function list3(Request $request)
    {
        $list = MasterModel::order('num','DESC')
            ->field('id,name,image,num')
            ->select();
        if (!$list){
            $this->error('暂无数据');
        }
        $this->success('查询成功',[
            'list' => $list
        ]);
    }

    //好评
    public function list4(Request $request)
    {
        $list = MasterModel::order('praise','DESC')
            ->field('id,name,image,num')
            ->select();
        if (!$list){
            $this->error('暂无数据');
        }
        $this->success('查询成功',[
            'list' => $list
        ]);
    }

    //师傅详情
    public function index(Request $request)
    {
        $id = input('id/d');
        if (empty($id)){
            $this->error('师傅ID未填写');
        }
        $order = MasterModel::field('id,image,range,num,age,textarea')->find($id);
        if (!$order){
            $this->error('该信息不存在');
        }
        $order1 = MastserModel::order('id','DESC')
            ->field('serve_name,price')
        ->where('master_id',$id)->select();
        if (!$order1){
            $this->error('该师傅未有服务');
        }
        $order2 = AppraModel::order('id','DESC')
            ->field('members_name,image,create_time,text,images')
            ->where('master_id',$id)->paginate(3);
        if (!$order2){
            $this->error('该师傅暂无评价');
        }
        $this->success('查询成功',[
            'list' =>[$order,$order1,$order2]
        ]);
    }

    //查看该师傅的全部评论
    public function index2(Request $request)
    {
        $id = input('id/d');
        if (empty($id)){
            $this->error('师傅ID未传输');
        }
        $order =  AppraModel::order('id','DESC')
            ->field('members_name,image,create_time,text,images,assess')
            ->where('master_id',$id)->select();
        if (!$order){
            $this->error('该师傅暂无评价');
        }
        $this->success('查询成功',$order);
    }

}